home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Software Contest 3 / FM Towns Software Contest 3.iso / exp / astral / a1 / game / source / afmain.c next >
C/C++ Source or Header  |  1994-01-07  |  12KB  |  564 lines

  1. // "afmain.c"
  2. // ASTRAL FORCE メインルーチン
  3.  
  4. #define MAIN
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <egb.h>
  8. #include <spr.h>
  9. #include <snd.h>
  10. #include <mos.h>
  11. #include <time.h>
  12. #include "wire3d.h"
  13. #include "sin8.c"
  14. #include "scmds.h"
  15.  
  16. // マクロ設定
  17.  
  18. #define LENGTH 1000
  19.  
  20. #define JOY_UP(A)     if((A&0x01)==0)
  21. #define JOY_DOWN(A)   if((A&0x02)==0)
  22. #define JOY_LEFT(A)   if((A&0x04)==0)
  23. #define JOY_RIGHT(A)  if((A&0x08)==0)
  24. #define JOY_TRIG_A(A) if((A&0x10)==0)
  25. #define JOY_TRIG_B(A) if((A&0x20)==0)
  26. #define JOY_SELECT(A) if((A&0x03)==0)
  27. #define JOY_RUN(A)    if((A&0x0c)==0)
  28.  
  29. // グローバル変数設定
  30.  
  31. static char Mwork[4096],Gwork[1536],Swork[16384];
  32.  
  33. extern WIRE_OBJECT Object[];
  34. extern int End_code;
  35.  
  36. extern int Count;
  37.  
  38. int Screen_mode=0;
  39.  
  40. int Sight_x,Sight_y;
  41. int Score=0;
  42. int High_score=0;
  43. int Shield;
  44.  
  45. int Laser=0;
  46. int Crush_time=0;
  47. int Start_time;
  48. int Laser_color=0;
  49.  
  50. char SE_crush[16000],SE_hit[1600],SE_dammage[6000];
  51.  
  52. int movdata[4096],demomov[4096];
  53.  
  54. extern int N_page,W_page;
  55. extern WIRE_SPACE Space[32];
  56. extern SCREEN_LOCATE Screen[32];
  57. extern int Hit_point[32];
  58. extern int Hit_size[32];
  59. extern int Hit_score[32];
  60. extern int Hit_my_fighter[32];
  61. extern int Offset[3];
  62. extern ANGLE Angle[3];
  63.  
  64. void screen_init(int mode)
  65. // mode...0:High.Normal 
  66. //        1:High.Wide
  67. //        2:Low .Normal
  68. //        3:Low .Wide
  69. {
  70.     int i;
  71.     
  72.     if(mode<0 || mode>3)
  73.         mode=0;
  74.     
  75.     switch(mode){
  76.     case 0:
  77.     case 1:
  78.         EGB_resolution(Gwork,0,5);
  79.         EGB_resolution(Gwork,1,5);
  80.         break;
  81.     case 2:
  82.     case 3:
  83.         EGB_resolution(Gwork,0,8);
  84.         EGB_resolution(Gwork,1,8);
  85.         break;
  86.     }
  87.     
  88.     for(i=0;i<2;i++){
  89.         EGB_writePage(Gwork,i);
  90.         EGB_clearScreen(Gwork);
  91.         EGB_displayStart(Gwork,1,0,0);
  92.         switch(mode){
  93.         case 0:
  94.         case 1:
  95.             EGB_displayStart(Gwork,0,64,0);
  96.             EGB_displayStart(Gwork,2,2,2);
  97.             break;
  98.         case 2:
  99.             EGB_displayStart(Gwork,0,32,0);
  100.             EGB_displayStart(Gwork,2,4,1);
  101.             break;
  102.         case 3:
  103.             EGB_displayStart(Gwork,0,0,0);
  104.             EGB_displayStart(Gwork,2,5,1);
  105.             break;
  106.         }
  107.         EGB_displayStart(Gwork,3,256,240);
  108.     }
  109.     
  110.     if(mode==1){
  111.         CRTC_out(0,80);
  112.         CRTC_out(1,590);
  113.         CRTC_out(4,669);
  114.         CRTC_out(29,3);
  115.         
  116.         CRTC_out(9,130);
  117.         CRTC_out(18,130);
  118.         CRTC_out(10,642);
  119.         
  120.         CRTC_out(11,130);
  121.         CRTC_out(22,130);
  122.         CRTC_out(12,642);
  123.     }
  124.     line(0,0,255,0,0x8000,2);
  125.     line(0,1,255,1,0x8000,2);
  126.     line(0,0,255,0,0x8000,3);
  127.     line(0,1,255,1,0x8000,3);
  128.     EGB_displayPage(Gwork,1,3);
  129. }
  130.  
  131. void movedata_anarize(char *source,int *movdata)
  132. {
  133.     int i,j=0,k=0,sgn=1;
  134.     
  135.     for(i=0;i<32768;i++){
  136.         switch(source[i]){
  137.         case '#':
  138.             while(source[++i]!='\n');
  139.             continue;
  140.         case ' ' :
  141.         case '\n':
  142.         case '\t':
  143.             continue;
  144.         case ',':
  145.             movdata[j++]=k*sgn;
  146.             k=0;
  147.             sgn=1;
  148.             continue;
  149.         case '-':
  150.             sgn=-1;
  151.             continue;
  152.         case '$':
  153.             return;
  154.         default:
  155.             if(source[i]>='0' && source[i]<='9'){
  156.                 k*=10;
  157.                 k+=source[i]-'0';
  158.             }
  159.             else{
  160.                 goto ERROR;
  161.             }
  162.             continue;
  163.         }
  164.     }
  165.     return;
  166.     ERROR:
  167.     printf("movファイルの書式に誤りがあります");
  168.     return;
  169. }
  170.  
  171. void title_demo_option(void){
  172.     int i,j,k;
  173.     
  174.     switch(Laser_color){
  175.     case 0:
  176.         Object[3].color=COLOR(16,31,0);
  177.         Object[2].color=COLOR(12,0,31);
  178.         Laser_color=1;
  179.         break;
  180.     case 1:
  181.         Object[2].color=COLOR(31,12,31);
  182.         Object[3].color=COLOR(31,31,16);
  183.         Laser_color=0;
  184.         break;
  185.     }
  186.     
  187.     MOS_rdpos(&i,&j,&k);
  188.     switch(i){
  189.     case 1:
  190.         End_code=1;
  191.         break;
  192.     case 2:
  193.         if((++Screen_mode)==4)Screen_mode=0;
  194.         screen_init(Screen_mode);
  195.         break;
  196.     }
  197.     if((pad_in()|0xc0)!=0xff){
  198.         End_code=2;
  199.     }
  200. }
  201.  
  202. void title_demo(void)
  203. {
  204.     int i,j,k;
  205.     
  206.     for(i=0;i<128;i++){
  207.         SPR_set_att(1023-i,1,1,0,0x2000);
  208.     }
  209.     SPR_set_att_pos(896+20,13,1,(128+147),0x8100,24,64);
  210.     // putstrg(80,64,896+20,"ASTRAL FORCE",12);
  211.     putstrg(56,168,896+34,"LEFT  BUTTON",12);
  212.     putstrg(56,180,896+46,"> GAME START        ",20);
  213.     putstrg(56,200,896+66,"RIGHT BUTTON",12);
  214.     putstrg(56,212,896+78,"> CHANGE SCREEN MODE",20);
  215.     
  216.     for(i=0;i<8;i++){ // スコア表示
  217.         SPR_set_att_pos(896+112+i,1,1,(128+2),0x8100,128+i*8,4);
  218.     }
  219.     SPR_set_att_pos(896+120,4,1,(128+143),0x8100,64,8);
  220.     
  221.     put_score(High_score);
  222.     
  223.     do{
  224.         MOS_rdpos(&i,&j,&k);
  225.     }while(i!=0);
  226.     
  227.     do{
  228.         Count=0;
  229.         pilot(demomov,title_demo_option);
  230.     }while(End_code==0);
  231.     return;
  232. }
  233.  
  234. int game_over(void)
  235. {
  236.     int i,j,k;
  237.     
  238.     switch(End_code){
  239.     case 0:
  240.         putstrg(92,64,896+20,"TIME OVER",9);
  241.         break;
  242.     case 1:
  243.         putstrg(60,64,896+20,"YOU ARE DESTROYED.",18);
  244.         clear_screen(W_page,COLOR(4,8,0));
  245.         star(Angle,W_page);
  246.         wirespace(Angle,Offset,32,W_page);
  247.         wait_VSYNC();
  248.         chgpage(W_page);
  249.         break;
  250.     }
  251.     if(Score>High_score){
  252.         High_score=Score;
  253.     }
  254.     do{
  255.         MOS_rdpos(&i,&j,&k);
  256.     }while(i!=0);
  257.     for(;;){
  258.         MOS_rdpos(&i,&j,&k);
  259.         if(i!=0){
  260.             Score=0;
  261.             End_code=0;
  262.             return 0;
  263.         }
  264.         if((pad_in()|0xc0)!=0xff){
  265.             return 1;
  266.         }
  267.     }
  268. }
  269.  
  270. void game_sub(void)
  271. {
  272.     int button,i;
  273.     
  274.     put_count(LENGTH-Count);
  275.     MOS_rdpos(&button,&Sight_x,&Sight_y);
  276.     SPR_set_pos(896+16,2,1,Sight_x,Sight_y);
  277.     Crush_time--;
  278.     SPR_set_att(896+0,4,4,128+46+Crush_time*16,0x8100);
  279.     
  280.     if(Crush_time==0){
  281.         SPR_set_pos(896+0,4,4,256,256);
  282.     }
  283.     
  284.     switch(Laser_color){
  285.     case 0:
  286.         Object[2].color=COLOR(12,0,31);
  287.         Object[3].color=COLOR(16,31,0);
  288.         Laser_color=1;
  289.         break;
  290.     case 1:
  291.         Object[2].color=COLOR(31,12,31);
  292.         Object[3].color=COLOR(31,31,16);
  293.         Laser_color=0;
  294.         break;
  295.     }
  296.     
  297.     if(Start_time!=0){
  298.         switch((Start_time>>2)%2){
  299.         case 0:
  300.             putstrg(108,80,896+20,"     ",5);
  301.             break;
  302.         case 1:
  303.             putstrg(108,80,896+20,"START",5);
  304.             break;
  305.         }
  306.         Start_time--;
  307.         return;
  308.     }
  309.     
  310.     switch(button){
  311.     case 1:
  312.         if(Laser==0){
  313.             line(0,255,Sight_x,Sight_y,COLOR(16,0,31),W_page);
  314.             line(4,255,Sight_x,Sight_y,COLOR(16,0,31),W_page);
  315.             line(2,255,Sight_x,Sight_y,COLOR(31,0,31),W_page);
  316.             line(251,255,Sight_x,Sight_y,COLOR(16,0,31),W_page);
  317.             line(255,255,Sight_x,Sight_y,COLOR(16,0,31),W_page);
  318.             line(253,255,Sight_x,Sight_y,COLOR(31,0,31),W_page);
  319.             Laser=1;
  320.         }
  321.         else{
  322.             Laser=0;
  323.         }
  324.         for(i=0;i<32;i++){
  325.             if(Hit_point[i]!=0 && Space[i].obj_no!=-1 && \
  326.              Sight_x>=Screen[i].locate[0]-Hit_size[i] && \
  327.              Sight_x<=Screen[i].locate[0]+Hit_size[i] && \
  328.              Sight_y>=Screen[i].locate[1]-Hit_size[i] && \
  329.              Sight_y<=Screen[i].locate[1]+Hit_size[i] && \
  330.              Screen[i].locate[2]>-(Object[Space[i].obj_no].size)){
  331.             SND_pan_set(70,Screen[i].locate[0]>>1);
  332.             SND_pcm_play_stop(70);
  333.             SND_pcm_play(70,70,127,SE_hit);
  334.                 if((--Hit_point[i])==0){
  335.                     SND_pan_set(71,Screen[i].locate[0]>>1);
  336.                     SND_pcm_play_stop(71);
  337.                     SND_pcm_play(71,60,127,SE_crush);
  338.                     Crush_time=2;
  339.                     if(Screen[i].locate[2]>3000){
  340.                     SPR_set_att_pos(896+0,4,4,128+46+Crush_time*16-32 , \
  341.                      0x8100,Screen[i].locate[0]-32,Screen[i].locate[1]-32);
  342.                     }
  343.                     else{
  344.                     SPR_set_att_pos(896+0,4,4,128+46+Crush_time*16, \
  345.                      0x8100,Screen[i].locate[0]-32,Screen[i].locate[1]-32);
  346.                      }
  347.                      Score+=Hit_score[i];
  348.                     if(Score<0){
  349.                         Score=0;
  350.                     }
  351.                     put_score(Score);
  352.                     Space[i].obj_no=-1;
  353.                     break;
  354.                  }
  355.             }
  356.         }
  357.         break;
  358.     }
  359.     
  360.     for(i=0;i<32;i++){
  361.         if(Hit_my_fighter[i]!=   0 && Space[i].obj_no!=-1 && \
  362.          Screen[i].locate[0]>=-150 && \
  363.          Screen[i].locate[0]<= 405 && \
  364.          Screen[i].locate[1]>=-150 && \
  365.          Screen[i].locate[1]<= 405 && \
  366.          Screen[i].locate[2]>=-500 && \
  367.          Screen[i].locate[2]<= 200 ){
  368.             SND_pan_set(70,64);
  369.             SND_pcm_play_stop(70);
  370.             SND_pcm_play(70,60,127,SE_dammage);
  371.              if((--Shield)==0){
  372.                  End_code=1;
  373.              }
  374.              put_shield(Shield);
  375.             Space[i].obj_no=-1;
  376.             clear_screen(N_page,COLOR(31,31,31));
  377.             break;
  378.         }
  379.     }
  380.     
  381.     if((pad_in()|0xc0)!=0xff){
  382.         End_code=2;
  383.     }
  384. }
  385.  
  386. void main(void)
  387. {
  388.     int i;
  389.     
  390.     FILE *str1;
  391.     
  392.     clock_t start_clock;
  393.     
  394.     char filebuf[32768];
  395.     
  396.     for(i=0;i<4096;i++){
  397.         Mwork[i]=0;
  398.     }
  399.     
  400.     printf("ASTRAL FORCE 30秒バージョン\n");
  401.     printf("Program : Version 0.11\n");
  402.     printf("Data    : Version 0.02\n");
  403.     
  404.     EGB_init(Gwork,1536);
  405.     SND_init(Swork);
  406.     MOS_start(Mwork,4096);
  407.     
  408.     screen_init(Screen_mode);
  409.     
  410.     SPR_init();
  411.     
  412.     SND_pcm_mode_set(2);
  413.     SND_elevol_mute(0x3f);
  414.     
  415.     str1=fopen("game.mov","r");
  416.     fread((void *)(filebuf),32768,1,str1);
  417.     fclose(str1);
  418.     movedata_anarize(filebuf,movdata);
  419.     
  420.     str1=fopen("demo.mov","r");
  421.     fread((void *)(filebuf),32768,1,str1);
  422.     fclose(str1);
  423.     movedata_anarize(filebuf,demomov);
  424.     
  425.     str1=fopen("crush.snd","rb");
  426.     fread((void *)(SE_crush),32768,1,str1);
  427.     fclose(str1);
  428.     
  429.     str1=fopen("hit.snd","rb");
  430.     fread((void *)(SE_hit),1600,1,str1);
  431.     fclose(str1);
  432.     
  433.     str1=fopen("dammage.snd","rb");
  434.     fread((void *)(SE_dammage),6000,1,str1);
  435.     fclose(str1);
  436.     
  437.     str1=fopen("sprdata.azc","rb");
  438.     if(str1==NULL){
  439.         printf("パレット設定ファイルの読出に失敗しました\n");
  440.         goto EXIT_main;
  441.     }
  442.     fread((void *)(filebuf),8192,1,str1);
  443.     fclose(str1);
  444.     SPR_setPaletteBlock(256,256,filebuf);
  445.     
  446.     str1=fopen("sprdata.azg","rb");
  447.     if(str1==NULL){
  448.         printf("パターン定義ファイルの読出に失敗しました\n");
  449.         goto EXIT_main;
  450.     }
  451.     fread((void *)(filebuf),32768,1,str1);
  452.     fclose(str1);
  453.     
  454.     MOS_pulse(8,8);
  455.     MOS_disp(0);
  456.     MOS_horizon(0,255);
  457.     MOS_vertical(0,239);
  458.     
  459.     // 照準 0-1
  460.     SPR_define(0,128+0,2,1,filebuf+128*(16*0+0));
  461.     
  462.     // 数字 2-11
  463.     for(i=0;i<10;i++){
  464.         SPR_define(0,128+2+i,1,1,filebuf+128*(16*1+i));
  465.     }
  466.     
  467.     // COUNT 12-13
  468.     SPR_define(0,128+12,2,1,filebuf+128*(16*4+2));
  469.     
  470.     // 文字 14-45
  471.     for(i=0;i<32;i++){
  472.         SPR_define(0,128+14+i,1,1,filebuf+128*(16*2+i));
  473.     }
  474.     
  475.     // 爆発 46-110
  476.     for(i=0;i<4;i++){
  477.         SPR_define(0,128+46+i*16,4,1,filebuf+128*(16*6+i*4));
  478.         SPR_define(0,128+50+i*16,4,1,filebuf+128*(16*7+i*4));
  479.         SPR_define(0,128+54+i*16,4,1,filebuf+128*(16*8+i*4));
  480.         SPR_define(0,128+58+i*16,4,1,filebuf+128*(16*9+i*4));
  481.     }
  482.     
  483.     // SCORE 122-123
  484.     SPR_define(0,128+122,2,1,filebuf+128*(16*4+0));
  485.     
  486.     // シールド表示の枠 124-132
  487.     SPR_define(0,128+124,4,1,filebuf+128*(16*4+4));
  488.     SPR_define(0,128+128,4,1,filebuf+128*(16*5+4));
  489.     
  490.     // シールド 132-133
  491.     SPR_define(0,128+132,1,1,filebuf+128*(16*4+8));
  492.     SPR_define(0,128+133,1,1,filebuf+128*(16*4+9));
  493.     
  494.     // カウント表示の枠 134-142
  495.     SPR_define(0,128+134,4,1,filebuf+128*(16*4+10));
  496.     SPR_define(0,128+138,4,1,filebuf+128*(16*5+10));
  497.     
  498.     // HIGH-SCORE 143-146
  499.     SPR_define(0,128+143,4,1,filebuf+128*(16*5+0));
  500.     
  501.     // タイトル文字 147-159
  502.     SPR_define(0,128+147,13,1,filebuf+128*(16*10+0));
  503.     
  504.     SPR_setOffset(-15,-7);
  505.     
  506.     SPR_display(1,128);
  507.     
  508.     for(;;){
  509.         title_demo();
  510.         if(End_code==2){
  511.             break;
  512.         }
  513.         End_code=0;
  514.         Count=0;
  515.         Shield=4;
  516.         
  517.         for(i=0;i<128;i++){
  518.             SPR_set_att(1023-i,1,1,0,0x2000);
  519.         }
  520.         
  521.         SPR_set_att_pos(896+16,2,1,(128+0) | 0x8000,0x8100,128,128);
  522.         SPR_set_att_pos(896+90,4,2,(128+134),0x8100,192,208);
  523.         for(i=0;i<5;i++){
  524.             SPR_set_att_pos(896+123+i,1,1,(128+2),0x8100,206+i*8,218);
  525.         }
  526.         for(i=0;i<8;i++){
  527.             SPR_set_att_pos(896+112+i,1,1,(128+2),0x8100,112+i*8,4);
  528.         }
  529.         SPR_set_att_pos(896+110,2,1,(128+122),0x8100,80,8);
  530.         SPR_set_att_pos(896+0,4,4,(128+40),0x8100,256,256);
  531.         SPR_set_att_pos(896+102,4,2,(128+124),0x8100,0,208);
  532.         SPR_set_att_pos(896+98,1,1,(128+132),0x8100,8,216);
  533.         for(i=0;i<3;i++){
  534.             SPR_set_att_pos(896+99+i,1,1,(128+133),0x8100,16+i*8,216);
  535.         }
  536.         
  537.         Start_time=32;
  538.         
  539.          put_shield(Shield);
  540.         
  541.         start_clock=clock();
  542.         pilot(movdata,game_sub);
  543.         start_clock=clock()-start_clock;
  544.         if(End_code==2){
  545.             break;
  546.         }
  547.         if(game_over()==1)break;
  548.         
  549.     }
  550.     
  551.     EXIT_main:
  552.     
  553.     SPR_display(0,2);
  554.     MOS_end();
  555.     SND_end();
  556.     
  557.     printf("End...\n");
  558.     printf("総実行時間  :%2.2f秒\n",(double)((double)start_clock/ \
  559.      (double)CLK_TCK));
  560.     printf("平均描画枚数:%2.2f枚/秒\n",(double)LENGTH / \
  561.      ((double)start_clock/(double)CLK_TCK));
  562. }
  563.  
  564.